#include <iostream>
#include <string>
using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    string x, y;
    bool flag = false;

    cin >> x >> y;
    for (int i = 0; i < x.size(); i++) {
      if (x[i] != y[i]) {
        if (flag) {
          if (x[i] > y[i]) {
            swap(x[i], y[i]);
          }
        } else {
          if (x[i] < y[i]) {
            swap(x[i], y[i]);
          }
        }
        flag = true;
      }
    }
    cout << x << "\n"
         << y << "\n";
  }
  return 0;
}